package com.lb.bs.client.adapter.proxy;

import com.lb.bs.client.adapter.proxy.cglib.LbInterceptor;
import org.springframework.cglib.proxy.Enhancer;

/**
 * program: LB-BS-Client
 * author: bsworld.xie
 * create: 2020-04-17 17:59
 * description:
 */
public class LBProxyFactory {

    public static <T> T getProxy(Class<T> clazz, Object originBean) {

        T proxy = null;
        try {
            proxy = create(clazz, originBean);
        } catch (Exception e) {
        }

        return proxy;
    }

    private static <T> T create(Class<T> clazz, Object originBean) throws IllegalAccessException, InstantiationException {
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(clazz);
        enhancer.setCallback(new LbInterceptor(originBean));
        T t = (T) enhancer.create();
        return t;
    }
}
